<template>
      <iframe
      :srcdoc="innerHTML"
      width="100%"
      height="100%"
      frameborder="0"
      allowfullscreen
    ></iframe>
</template>

<script setup>
import { ref } from "vue";
import { useRoute } from "vue-router";
import EventBus from "@/utils/eventBus.js";
import { postplay } from "@/utils/api/customerService/index.ts";

const route = useRoute();

const innerHTML = ref('');
const balance = route.query.money;
const initHmtl = () => {
  if(balance > 9999){
    EventBus.emit("openToastBox", ["金额不能大于9999"]);
    return;
  }
  //测试环境可以充值0.01
  const { public: { envUrl } } = useRuntimeConfig()
  if (envUrl === 'production'){
    const regex = /\./;
    if(regex.test(balance)){
      EventBus.emit("openToastBox", ["金额只能是整数"]);
      return;
    }
  }
  postplay({
    balance: balance,
    use_type: 3
  }).then((res) => {
    innerHTML.value = res.data.value;
  })
}
onMounted(() => {
  if(process.client){
    nextTick(() => {
      initHmtl();
    })
  }
})
</script>

<style lang="scss" scoped>
</style>
